//
//  Comman.swift
//  Microblog
//
//  Created by Roman on 17/1/7.
//  Copyright © 2017年 Roman. All rights reserved.
//

import UIKit

let client_id = "354511372"


let client_secret = "71a8d3b0d47e2426a0f4c14a5e94ccc7"

//回调地址
let redirect_uri = "https://git.oschina.net/Romam"


//屏幕尺寸信息
let ScreenWidth = UIScreen.main.bounds.width
let ScreenHeight = UIScreen.main.bounds.height

		
//进行通知的拓展.
extension NSNotification.Name {
    
   static let AppChangRootVC = Notification.Name("AppChangeRootViewController")
    
    
}

//截取屏幕视图
extension UIImage{
    
    class func snapshotCurrentScreen() -> UIImage{
        //1.开启图形上下文
        let window = UIApplication.shared.keyWindow!
        UIGraphicsBeginImageContextWithOptions(window.bounds.size, false, 0)
        
        //2.将window 绘制到图层中
        window.drawHierarchy(in: window.frame, afterScreenUpdates: true)
        //3. 从上下文中获取图片对象
        let image = UIGraphicsGetImageFromCurrentImageContext()
        //3.1 关闭图形上下文
        UIGraphicsEndImageContext()
        //4.返回结果
        return image!
    }
    
    //图片的缩放.用于减少指定的宽度和高度
    func scaleImage(width: CGFloat) -> UIImage {
        //获取图片的宽高
        let imageW = self.size.width
        let imageH = self.size.height
        //判断屏幕宽度,如果比屏幕大,则需要缩小,否者不需要
        if imageW < width {
            return self
        }
        //需要缩放图片,先等比例获取
        let scaleH = imageH / imageW * width
        let imagebounds = CGRect(x: 0, y: 0, width: width, height: scaleH)
        //然后开启图形上下文来获取图片
        UIGraphicsBeginImageContextWithOptions(imagebounds.size, false, 0)
        self.draw(in: imagebounds)
        let image = UIGraphicsGetImageFromCurrentImageContext()
        
        UIGraphicsEndImageContext()
        
        return image!
        
        
        
        
    }
    
    
    
}

//进行cell 的随机色设定,定义一个随机色
extension UIColor {
    class var randomColor: UIColor{
        let r = CGFloat(arc4random() % 256) / 255.0
        let g = CGFloat(arc4random() % 256) / 255.0
        let b = CGFloat(arc4random() % 256) / 255.0
        return UIColor(red: r, green: g, blue: b, alpha: 1)
    }
    
    

}

